/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cluelessserver;

import java.util.ArrayList;



/**
 * Constructs a Board space.
 * 
 */
public class BoardSpace {
    BoardSpace roomNorth;
    BoardSpace roomSouth;
    BoardSpace roomWest;
    BoardSpace roomEast;
    BoardSpace roomSecret;
    String name = "";
    Boolean isRoom;
    Boolean isNotBlocked = true;
    
    public String toString(){
        return name;
    }
    
    /**
     * returns room to the north. Returns null is there is no room there.
     * @return room to the north
     */
    BoardSpace getRoomNorth(){
        return roomNorth;
    }
    BoardSpace getRoomSouth(){
        return roomSouth;
    }
    BoardSpace getRoomWest(){
        return roomWest;
    }
    BoardSpace getRoomEast(){
        return roomEast;
    }
    BoardSpace getRoomSecret(){
        return roomSecret;
    }

    /**
     * Used for linking rooms on the board
     * 
     * @param rmNorth room to the north to link
     * @param rmSouth
     * @param rmWest
     * @param rmEast
     * @param rmSecret 
     */
    
    public void makeConnections(BoardSpace rmNorth, BoardSpace rmSouth, BoardSpace rmWest, BoardSpace rmEast, BoardSpace rmSecret){
        roomNorth = rmNorth;
        roomSouth = rmSouth;
        roomWest = rmWest;
        roomEast = rmEast;
        roomSecret = rmSecret;
    }
    
    
//    public ArrayList<BoardSpace> getPossibleMoves(){
//        ArrayList<BoardSpace> moves = new ArrayList();
//        if(isValid(roomNorth)){
//            moves.add(roomNorth);
//        }
//        if(isValid(roomSouth)){
//            moves.add(roomSouth);
//        }
//        if(isValid(roomWest)){
//            moves.add(roomWest);
//        }
//        if(isValid(roomEast)){
//            moves.add(roomEast);
//        }
//        if(isValid(roomSecret)){
//            moves.add(roomSecret);
//        }    
//        return moves;
//    }
    
    /**
     * Builds a string of valid moves used for sending to the client. Checks there is a room in the direction indicated and that it is not blocked.
     * @return string of room names separated by a space
     */
    public String getMovesToString(){
        String moves = "";
        boolean isFirstMove = true;
        if(isValid(roomNorth)){
            moves += "North";
            isFirstMove = false;
        }
        if(isValid(roomSouth)){
            if (!isFirstMove){
                moves += " ";
            }
            moves += "South";
            isFirstMove = false;
        }
        if(isValid(roomWest)){
            if (!isFirstMove){
                moves += " ";
            }
            moves += "West";
            isFirstMove = false;
        }
        if(isValid(roomEast)){
            if (!isFirstMove){
                moves += " ";
            }
            moves += "East";
            isFirstMove = false;
        }
        if(isValid(roomSecret)){
            if (!isFirstMove){
                moves += " ";
            }
            moves += "Secret";
        }        
        return moves;
    }
    
    /**
     * Returns whether the room exists and whether it is blocked (occupied hallway)
     * @param rm BoardSpace to check
     * @return whether the space can be entered
     */
    boolean isValid(BoardSpace rm){
        return (rm != null && rm.isNotBlocked);
    }
}
